<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>添加收款通道</title>
	<link rel="stylesheet" href="/component/pear/css/pear.css" />
	<style>
		.inputTxt {
			margin-left: 10px;
		}
	</style>
</head>

<body>
	<form id="add-account" class="layui-form layui-form-pane" action="" lay-filter="add-account">
		<div class="mainBox">
			<div class="main-container">
				<div class="layui-form-item">
					<label class="layui-form-label">收款平台</label>
					<div class="layui-input-block">
						<select name="platform">
							<option value="">收款平台</option>
							<option value="wxpay">微信支付</option>
							<option value="alipay">支付宝</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">收款通道</label>
					<div class="layui-input-block">
						<select name="password">
							<option value="">请选择</option>
							<optgroup label="微信支付">
								<option value="wx1">个人码</option>
								<option value="wx2">赞赏码</option>
								<option value="wx3">经营码</option>
								<option value="wx4">商家码</option>
							</optgroup>
							<optgroup label="支付宝">
								<option value="al1">个人码</option>
								<option value="al2">经营码</option>
							</optgroup>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">收款账号</label>
					<div class="layui-input-block">
						<input type="text" name="account" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
		</div>
		<div class="bottom">
			<div class="button-container">
				<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
					lay-filter="add-account">
					<i class="layui-icon layui-icon-ok"></i>
					提交
				</button>
				<button type="reset" class="pear-btn pear-btn-sm">
					<i class="layui-icon layui-icon-refresh"></i>
					重置
				</button>
			</div>
		</div>
	</form>
	<script src="/component/layui/layui.js"></script>
	<script src="/component/pear/pear.js"></script>
	<script>
		layui.use(['form'], function () {
			let form = layui.form;
			form.on('submit(add-account)', function (obj) {
				const field = obj.field;
				(async () => {
					const url = '/api/PayManage/addCode';
					const info = field;
					const res = await fetch(url, { method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(info) });
					if (res.status !== 200) {
						layer.msg('请求失败，请重试！', { tips: 2, time: 1200 });
						return false;
					}
					const rec_info = await res.json();
					if (rec_info.code === 0) {
						layer.msg(rec_info.msg, { icon: 1, time: 1200 }, () => {
							parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
							parent.layui.table.reload("account-table");
						});
					} else {
						layer.msg(rec_info.msg, { icon: 2, time: 1200 });
					}
				})()
				return false;
			});
		})
	</script>
</body>

</html>